package com.test.mapper;

import com.test.pojo.Category_;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

@Mapper
public interface CategoryMapper {
    @Select("select * from category_ order by id desc ")
    List<Category_> findAll();

    @Insert("insert into category_ ( name ) values (#{name})")
    int insertCategory(Map<String , Object> m) ;


    @Update("update category_ set name=#{name} where id=#{id}")
    int updateCategory(@Param("name") String name , @Param("id") int id ) ;

    @Delete("delete from category_ where id=#{id}")
    int delete(int id ) ;

    @Select({"<script>",
            "select * from category_ ",
            "where 1 =1",
            "<if test='id!=null'>" ," and id=#{id}" ,"</if>",
            "<if test='name!=null'>" ," and name=#{name}" ,"</if>",
            "order by id desc ",
            "</script>"})
    List<Category_> findByName (@Param("id") Object id , @Param("name") String name );


    @Select({"<script>" ,
            "select count(*) from category_",
            "where 1=1 " ,
            "<if test='name!=null'>","and name=#{nmae}","</if>",
            "</script>"})
    int count(@Param("name") String name);


}
